package com.ssm.util.test.base;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


/**
 * 值传递和引用传递
 * @author Administrator
 *
 */
public class StringUtil {
	
	public static void test(){
		String s1="hello";
		String s2="world";
		System.out.println(s1+"---------"+s2);//hello---------world
		change(s1, s2);//基本类型封装类值传递,s1是值，修改形参不影响实参
		System.out.println(s1+"---------"+s2);//hello---------world
		StringBuffer sb1=new StringBuffer("hello");
		StringBuffer sb2=new StringBuffer("world");
		System.out.println(sb1+"---------"+sb2);//hello---------world
		change(sb1, sb2);//引用传递,sb1是对象的引用，修改形参会修改实参
		System.out.println(sb1+"---------"+sb2);//hello---------worldworld
	}

	public static void change(String s1,String s2) {
		s1=s2;
		s2=s1+s2;
	}
	
	public static void change(StringBuffer sb1,StringBuffer sb2) {
		sb1=sb2;
		sb2=sb1.append(sb2);//append是sb1添加字符串
	}
	
	public static void  testlist() {
		ArrayList<String> arrayList = new ArrayList<String>();
		List<List<String>> linkedList =  new LinkedList();
		arrayList.add("before add");
		linkedList.add(arrayList);
		arrayList.add("after add");
		System.out.println(linkedList);
		
//		LinkedList<String> lList = new LinkedList<String>();
		
		
	}
	
	public static void main(String[] args) {
//		test();
		testlist();
	}
}
